package com.fms.gui.templateCreator;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class CreateTemplateForm extends JFrame implements ActionListener
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 759149091454203783L;
	
	
	public CreateTemplateForm(  JComponent selector,
								 JButton creator)
	{
		this.setLayout(new BorderLayout());		
				
		
		this.add(selector, BorderLayout.CENTER);
		this.add(creator, BorderLayout.SOUTH);		
		
		int minimumHeight = (int)(creator.getPreferredSize().getHeight() + 20 + selector.getPreferredSize().getHeight());
		
		int minimumWidth =  (int)(selector.getPreferredSize().getWidth());
		
		this.setMinimumSize(new Dimension(minimumWidth, minimumHeight));
		this.setSize(new Dimension(minimumWidth, minimumHeight));
		this.setName("Create a FlowSheet");
		creator.addActionListener(this);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.centerScreen();
	}
	
	public void centerScreen() 
	{
		  Dimension dim = getToolkit().getScreenSize();
		  Rectangle abounds = getBounds();
		  setLocation((dim.width - abounds.width) / 2,
		      (dim.height - abounds.height) / 2);
	}

	@Override
	public void actionPerformed(ActionEvent arg0)
	{
		this.setVisible(false);		
	}

}
